import django
django.setup()
from time import timezone
# Create your tests here.
from serverworker.models import testmod
from  serverworker import models
from django.db import IntegrityError
import os
import  uuid
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'matrix.settings')  # 添加了环境
from django.test import TestCase

# Create your tests here.
from django.test import TestCase

# Create your tests here.

# -*- coding: utf-8 -*-

from django.http import HttpResponse


'''

from serverworker.models import aa


# 数据库操作：添加数据
def testdb(request):
    test1 = aa(name='lijun')
    test1.save()
    return HttpResponse("<p>数据添加成功！</p>")

# 数据库操作：获取数据
def querry(request):
    # 初始化
    response = ""
    response1 = ""

    # 通过objects这个模型管理器的all()获得所有数据行，相当于SQL中的SELECT * FROM
    list = aa.objects.all()

    # filter相当于SQL中的WHERE，可设置条件过滤结果
    response2 = aa.objects.filter(id=1)

    # 获取单个对象
    response3 = aa.objects.get(id=1)

    # 限制返回的数据 相当于 SQL 中的 OFFSET 0 LIMIT 2;
    aa.objects.order_by('name')[0:2]

    # 数据排序
    aa.objects.order_by("id")

    # 上面的方法可以连锁使用
    aa.objects.filter(name="runoob").order_by("id")

    # 输出所有数据
    for var in list:
        response1 += var.name + " "
    response = response1
    return HttpResponse("<p>" +"查询数据库返回的数据为："+ response + "</p>")
'''

def main():

    testmod.objects.create(name='runoob')

def test1():
    data = [[1, 2, 3, 4], [1, 2, 3, 4]]
    records = [(x[1], x[2], x[3]) for x in data]
    print(records)
    with open('C:/Users/STATION/Pictures/rss1.png', 'rb') as f:
        image_data = f.read()
    print(image_data)

if __name__ == '__main__':
    id = 'bb5cf0a68e4572a5'
    lis_all = []
    #head
    res = models.Device_attribute.objects.filter(device_name= id, status=1, is_head=1).all()[0]
    lis_all.append([res.a1, res.b1, res.c1, res.d1, res.e1, res.f1, res.g1, res.h1, res.notes, res.create_time,res.order_id])
    #data
    res = models.Device_attribute.objects.filter(device_name= id, status=1, is_head=0 ).all()
    for i in res:
        lis_all.append([i.a1, i.b1, i.c1, i.d1, i.e1, i.f1, i.g1, i.h1, i.notes, i.create_time, i.order_id])
    print(lis_all)
